import { getLocalStorage } from '@/utils/localStorage'
// "DeviceType":"xuhui-face",
// "DeviceType":"dzybpz",
// "DeviceType":"ycxyy",
// "DeviceType":"wzsmk",
// "DeviceType": "wzsmk3th",
// "DeviceType": "ybpzsmk",
let defaultType = [
  {
    type: 'wzsmk',
    name: '市民卡'
  },
  {
    type: 'dzybpz',
    name: '医保凭证',
    data: {
      BusinessType: '01301', // 交易类型，01202，必填
      HospCode: 'H330302000034', // 医院代码
      OfficeId: '001', // 医保科室编号，可为空
      OfficeName: '超声科', // 科室名称，可为空
      OperatorId: '01201', // 操作员工号
      OperatorName: 'PACS', // 操作员姓名
      WebServer: '100.72.5.131', // 驱动INI配置项，可为空
      Port1: '2981', // 驱动INI配置项，可为空
      Port2: '2981', // 驱动INI配置项，可为空
      PortDzpz: '8004', // 驱动INI配置项，可为空
      TermId: '001', // 终端ID,可为空 001
      SendKeys:'' // 医保凭证编码
    }
  },
  {
    type: 'jkk',
    name: '健康卡',
    isHide: 'true',
    data: { operatorCode: '123', operatorName: 'admin', qrcode_info: '123456789abcdefg:0:123:456' }
  },
  {
    type: "jyzs",
    name: "就医助手",
    isHide: 'true',
    Data: {
      Msg: "FEQR54B0DFEB6D5946EC8DA1A50F5D95D31F33C925D2488360E0277E7857146BA65C7DE4D04E07FF6F652C960118CB66E332D42CBD3F33C4AFD4"
    }
  }
]
let types = ''
if (window.g.applyInfoHospital == 'fuding') {
  types = window.g.KYCARDREADER_OPTIONS_FUDING
} else {
  types = window.g.KYCARDREADER_OPTIONS || defaultType
}
const getTypeData = (type, readerCardOption) => {
  let to = readerCardOption || types
  const o = to.find((item) => {
    if (Array.isArray(item.type) && item.type.indexOf(type) > -1) {
      // console.log('福鼎市医院的市民卡')
      var index = getLocalStorage('defaultReadCard') || 0
      const data = item.data || item.Data
      return {
        type: item.type[index],
        name: item.name,
        data: data[index]
      }
    } else if (item.type == type) {
      return item.type === type
    } else {
      return item.type === type
    }
  })
  let result = '' // o ? o.data : null
  if (o && (o.data || o.Data)) {
    result = o.data || o.Data
  } else {
    result = null
  }
  if (result == null) {
    // result = {
    //   SendKeys: ''
    // }
  } else {
    if (typeof result == 'object' && (type == 'dzybpz' || type == 'dzybpz-tz' || type == 'dzybpz-fj')) {
      result.SendKeys = ''
    }
  }
  if (type == 'wzsmk') {
    result = {
      mode: 0
    }
    console.log('result.mode', result.mode)
  }
  return result
}
const getTypeOptions = (readerCardOption) => {
  let options = readerCardOption || types || defaultType
  options.forEach((item, i) => {
    if (Array.isArray(item.type)) {
      console.log('defualtReadCard读卡', getLocalStorage('defaultReadCard'))
      var index =  ~~(getLocalStorage('defaultReadCard'))
      console.log('index读卡', index)
      options[i] = {
        type: item.type[index],
        name: item.name,
        data: item.data[index]
      }
      if (item.isHide) {
        options[i].isHide = item.isHide
      }
      if (item.numSlice) {
        options[i].numSlice = item.numSlice
      }
    }
  })
  return options
}

export default {
  types,
  defaultType,
  getTypeOptions,
  getTypeData
}
